package cn.yunyichina.provider.hisiface.invoke.openservice;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.yunyichina.provider.framework.dubbo.service.OrderService;
import cn.yunyichina.provider.hisiface.invoke.IOutsideInvoke;
import cn.yunyichina.provider.iface.entity.common.ResCommon;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.provider.iface.entity.order.facepay.FacepayResponseVO;
import cn.yunyichina.utils.convert.JsonUtils;

import com.alibaba.fastjson.JSON;

/**
 * 当面付
 * 
 * @author zhou
 *
 */
public class TradePayService implements IOutsideInvoke {

	static Logger logger = LoggerFactory.getLogger(TradePayService.class);

	@Override
	public String execute(Map<String, String> params) {
		String paramsStr = JSON.toJSONString(params);
		logger.info("openService:tradePay 接收到前置机的入参: {}", paramsStr);

		ResCommon<FacepayResponseVO> facepayResponse = OrderService.getOrderClient().openapiFacepay(paramsStr);
		logger.info("openService:tradePay 接收到的返回: {}", JsonUtils.toJsonString(facepayResponse));

		Response response = new Response(facepayResponse.getResultCode(), facepayResponse.getResultMessage());
		if (response.isSuccess()) {
			response.setResult(JsonUtils.toJsonString(facepayResponse.getResult()));
		}
		String result = JsonUtils.toJsonString(response);
		logger.info("openService:tradePay 返回给前置机: {}", result);

		return result;
	}

}
